Multilingual support

Overview

You can switch the display language in Next Design. The extension can be made multilingual by adding logic to the implementation code so that the display language of the extension also switches in conjunction with the switching.

In addition, extension support for multiple languages is optional. If you do not need multilingual support, the following support is not required.

To support the extension in multiple languages, first create a locale file that defines resource strings for each display language. And it can be realized by adding/changing the logic to acquire the resource string corresponding to the display location from those locale files to the implementation code. In this way, adding and changing the implementation code to support multiple languages is called globalization.

Creating a locale file

  • You can define the resource string for each display language by adding the locale file with the following name to the folder where the manifest exists.

    File name format: locale.{lang}.json

    Language lang File Name
    Japanese ja locale.ja.json
    English en locale.en.json
  • Use UTF-8 as the character code of the locale file.

Locale file implementation example

```json tab="locale.ja.json" { "locale": "ja", "resourceStrings" :{ "MyExt.Tab.Label": "Extension", "MyExt.ValidationGroup.Label": "Model validation", "MyExt.ValidationButton.Label": "Validation", "MyExt.ValidationButton.Description": "Validate all models", "MyExt.Error.CanNotBeEmpty.Title": "Cannot be empty", "MyExt.Error.CanNotBeEmpty.Message": "Name field cannot be empty", "MyExt.Error.CanNotChange.Message2": "{0} cannot be {1}" } }


```json tab="locale.en.json"
{
    "locale": "en",
    "resourceStrings" :{
        "MyExt.Tab.Label": "Extension",
        "MyExt.ValidationGroup.Label": "Model Validation",
        "MyExt.ValidationButton.Label": "Validate",
        "MyExt.ValidationButton.Description": "Validate all models.",
        "MyExt.Error.CanNotBeEmpty.Title": "Can't be empty.",
        "MyExt.Error.CanNotBeEmpty.Message": "Name field can't be empty.",
        "MyExt.Error.CanNotChange.Message2": "Can't set {0} to {1}."
    }
}

Globalizing strings in the manifest

  • Instead of specifying the character string directly in the manifest, by specifying with "% resource string name %", it will be replaced with the resource string defined in the locale file.
  • If the corresponding resource string name does not exist in the locale file, "% resource string name %" is displayed as is.

manifest.json

{
  "extensionPoints": {
    "ribbon": {
      "tabs": [
        {
          "id": "MyExtensions.Tab",
          "label": "%MyExt.Tab.Label%",
          "groups": [
            {
              "id": "MyExtensions.ValidationGroup",
              "label": "%MyExt.ValidationGroup.Label%",
              "controls": [
                {
                  "type": "Button",
                  "id": "MyExtensions.ValidationButton",
                  "label": "%MyExt.ValidationButton.Label%",
                  "description": "%MyExt.ValidationButton.Description%",
                  "imageLarge": "resources/icon.png",
                  "command": "Validate.Run"
                }
              ]
            }
          ]
        }
      ]
    }
  },
}

Globalizing strings in handlers

Get the resource string from the locale file as follows:

Simple resource string

    var title = context.GetResourceString("MyExt.Error.CanNotBeEmpty.Title");
    var message = context.GetResourceString("MyExt.Error.CanNotBeEmpty.Message");
    model.AddError("Name","Error",title,message);

Parameter embedded resource string

    var title = context.GetResourceString("MyExt.Error.CanNotBeEmpty.Title");
    var message = context.GetResourceString2("MyExt.Error.CanNotChange.Message2","aaa","bbb");
    model.AddError("Name","Error",title,message);

Resource string acquisition API

public interface IContext
{
    //Get the resource string for the current culture
    string GetResourceString(string key);
    string GetResourceString1(string key,string param1);
    string GetResourceString2(string key,string param1,string param2);
    string GetResourceString3(string key,string param1,string param2,string param3);
}